#pragma once

#include "IOphies.h"
#include "ExampleDcmOphiesCallback.h"
#include "OphiesDownLoadWnd.h"

class COphies : public IOphies
{
public:
	COphies();
	virtual ~COphies();

	//virtual Function.
public:
	//Initialize
	virtual BOOL	Init();
	virtual BOOL	IsInit()						{ return m_bInitialized; }
	virtual void	Destroy();

	virtual void	SetNotifyWnd(CWnd* pWnd)		{ m_pNotifyWnd = pWnd; }
	virtual CWnd*	GetNotifyWnd()					{ return m_pNotifyWnd; }

	//Get Exam List
	virtual BOOL	GetStudy(CString strUID = _T(""));
	virtual BOOL	GetSeries(int dcm_study_key);
	virtual BOOL	GetInstance(int dcm_series_key);
	virtual BOOL	GetDocSet();
	virtual BOOL	GetPatient();

	//Set Instance Status
	virtual void	SetStatusIdle()					{ m_nStatus = TYPE_NONE; }
	virtual void	SetStatus(int nStatus)			{ m_nStatus = nStatus; }
	virtual int		GetStatus()						{ return m_nStatus; }

	//Instance Function.
	virtual	int		GetStudyCount();
	virtual CInstanceStudy* GetInstanceStudy(int nIndex);

	//Open Exam
	virtual BOOL	OpenExam(CStringArray& arrInstancePath);

	//Make Instance List
	void	ResultCallBack(QList<ophies::DataModel*>* list);

	void	AddInstanceStudy(CInstanceStudy* pInstance);
	void	AddInstanceSeries(CInstanceSeries* pInstance);
	void	AddInstanceImage(CInstanceImage* pInstance);
	void	AddInstanceDocSet(CInstanceDocSet* pInstance);
	void	AddInstancePatient(CInstancePatient* pInstance);
	

protected:
	void	InitInternal();
	void	DestroyInternal();

	void	BindInstanceStudy(DcmStudy* pStudy);
	void	BindInstanceSeries(DcmSeries* pSeries);
	void	BindInstanceImage(DcmInstance* pInstance);
	void	BindInstanceDocSet(Docset* pDocSet);
	void	BindInstancePatient(Patient* pPatient);

	BOOL	BuildRelationShips(QList<ophies::DataModel*>* list);

protected:
	ExampleDcmStudiesCallback*		m_pStudyCallback;
	ExampleDcmSeriesCallback*		m_pSeriesCallback;
	ExampleDcmInstancesCallback*	m_pInstanceCallback;
	ExampleDocsetsCallback*			m_pDocSetCallback;
	ExamplePatientsCallback*		m_pPatientCallback;

	BOOL					m_bInitialized;

	int						m_nStatus;			
	int						m_nDownLoadIndex;

	CWnd*					m_pNotifyWnd;

	CInstanceInternal*		m_pInternal;

	CDownLoadWndArray		m_arrDownLoadWnd;
};
